"use strict";

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

(function () {
    var template = function template(self) {
        return "<aux-view class=\"aux-date\"></aux-view>";
    };

    function handleNewValue(self, newval) {
        var $value = "";
        if (!newval) {
            return;
        }
        if ((typeof newval === "undefined" ? "undefined" : _typeof(newval)) == "object" && newval instanceof Date) {
            $value = newval;
        } else {
            $value = new Date(parseFloat(newval));
        }
        self.$value = $value;
    }

    function setContent(self) {
        if (!self.$format) {
            self.$ele.root.textContent = self.$value.toLocaleString();
        } else {
            self.$ele.root.textContent = self.$value.auiFormat(self.$format);
        }
    }

    document.auiDefineElement("aux-date", {
        template: template,
        props: {
            "value": {
                afterCreated: function afterCreated(self, newval) {},
                observer: function observer(self, oldval, newval) {
                    handleNewValue(self, newval);
                    setContent(self);
                },

                observerProp: function observerProp(self) {
                    return {
                        get: function get() {
                            return self.$value;
                        },
                        set: function set(newval) {
                            handleNewValue(self, newval);
                            setContent(self);
                        }
                    };
                }
            },
            "format": {
                afterCreated: function afterCreated(self, newval) {
                    self.$format = newval;
                    handleNewValue(self, self.auiGetAttribute("value"));
                    setContent(self);
                },
                observer: function observer(self, oldval, newval) {
                    self.$format = newval;
                    setContent(self);
                }
            }
        },
        created: function created(self) {
            self.$ele.root = self.children[0];
            self.$value = new Date();
        }
    });
})();